# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Stefan Husmann <stefan-husmann@t-online.de>
# Contributor: Robson Peixoto <robsonpeixoto@gmail.com>

pkgname=bibtool
pkgver=2.68
pkgrel=5
pkgdesc="A tool for manipulating BibTeX files"
arch=('loong64' 'x86_64')
url="http://www.gerd-neugebauer.de/software/TeX/BibTool/en/"
license=('GPL2')
depends=('glibc' 'texlive-bin')
makedepends=('texlive-core')
source=(
  "https://github.com/ge-ne/bibtool/releases/download/BibTool_${pkgver//./_}/BibTool-$pkgver.tar.gz"{,.asc}
  'old-font-commands-added.patch::https://github.com/ge-ne/bibtool/commit/c61cf667bdf846a2ad5079a8eae7fc863389f71b.patch'
)
sha512sums=('ab71d86cb363c755388c6ce2b546b0a6863eefc48688ebe482eef9839a42ecb3d39b8c30d33cf925dd22080fea111225075e12e8bcc917728fa67b32699f0b91'
            'SKIP'
            'de4467540c10df4480c3a679a84da7670df722278117e7ee7de2f756de31e19ed451ceb3947290340912bdaef88e0f08f4f8ea84c3049d2865d01451e90f1421')
b2sums=('d96e9c6b67994647d43c5e5fb2c206eafc04703d2c9af36fd329af583ef7daae0b3412d3e4abd6a6e9eb7ec65cd36412cddcecd7c1494358a6c8416e38cd9e91'
        'SKIP'
        'c89b4ad46c392c3df83f849ef6fe267a56f39f579551e4dc909e5a0259e5d62bed934f40f840e61765e40f3b44d86b352b4ab3301d99d31fbb59850c585eb4b3')
validpgpkeys=('E2A609830CE1675666671B86EA2168BE699213A2') # Gerd Neugebauer <gene@gerd-neugebauer.de>

prepare() {
  cd BibTool

  patch -p1 -i ../old-font-commands-added.patch
}

build() {
  cd BibTool

  autoreconf
  ./configure --prefix=/usr
  make all doc
}

package() {
  cd BibTool

  # if not done, makefile installs the binary to /usr/bin instead of /usr/bin/bibtool
  install -vd "$pkgdir/usr/bin"
  
  # when INSTALL is not specified, makefile installs man files with 0755 permissions
  make INSTALLPREFIX="$pkgdir" INSTALL='install -p -m 755' install 
  make INSTALLPREFIX="$pkgdir" INSTALL='install -p -m 644' install-man

  # documentation
  for _i in doc/*.pdf; do
    install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" "$_i"
  done
}
